<?php

$container_bl=join('&nbsp;', $form->_button_container['BL']);
$container_br=join('&nbsp;', $form->_button_container['BR']);
$container_tr=join('&nbsp;', $form->_button_container['TR']);

$cliente=$form->cliente->value;
$id=$this->datasis->dameval("SELECT id FROM scli WHERE cliente='$cliente'");

if ($form->_status=='delete' || $form->_action=='delete' || $form->_status=='unknow_record'):
	echo $form->output;
else:

$campos=$form->template_details('itnotascc');
$scampos  ='<tr id="tr_itnotascc_<#i#>">';
$scampos .='<td class="littletablerow" align="left" >'.$campos['codigo']['field'].'</td>';
$scampos .='<td class="littletablerow" align="left" >'.$campos['desca']['field'].'</td>';
$scampos .='<td class="littletablerow" align="left" >'.$campos['unidad']['field'].'</td>';
$scampos .='<td class="littletablerow" align="right">'.$campos['cana']['field'].  '</td>';
$scampos .='<td class="littletablerow" align="right">'.$campos['preca']['field']. '</td>';
$scampos .='<td class="littletablerow" align="right">'.$campos['importe']['field'];
$scampos .= '<td class="littletablerow"><a href=# onclick="del_itnotascc(<#i#>);return false;">'.img("images/delete.jpg").'</a></td></tr>';
$campos=$form->js_escape($scampos);

if(isset($form->error_string)) echo '<div class="alert">'.$form->error_string.'</div>';

$ivap=$this->datasis->traevalor('IVAP');

echo $form_scripts;
echo $form_begin;

$link=base_url()."common/numnotasdc/";

if($form->_status!='show'){ ?>
<script language="javascript" type="text/javascript">
var itnotascc_cont=<?php echo $form->max_rel_count['itnotascc']; ?>;

$(function(){
	$(".inputnum").numeric(".");
	totalizar();

});
function importe(id){
	var ind     = id.toString();
	var cana    = Number($("#cana_"+ind).val());
	var preca   = Number($("#preca_"+ind).val());
	var importe = roundNumber(cana*preca,2);
	$("#importe_"+ind).val(importe);

	totalizar();
}

function totalizar(){
	var iva    =0;
	var totalg =0;
	var totals =0;
	var ivap =18;
	var importe=0;
	var cana   =0;
	var arr=$('input[name^="importe_"]');
	jQuery.each(arr, function() {
		nom=this.name;
		pos=this.name.lastIndexOf('_');
		if(pos>0){
			ind     = this.name.substring(pos+1);
			cana    = Number($("#cana_"+ind).val());
			itiva   = Number($("#itiva_"+ind).val());
			importe = Number(this.value);	
			totals  = (totals+importe);
			
		}
	});
	
	iva     = (totals*ivap/100);
	
	$("#totals").val(roundNumber(totals,2));
	$("#totals_val").text(nformat(totals,2));
			
	$("#iva").val(roundNumber(iva,2));
	$("#ivat_val").text(nformat(iva,2));
	
	$("#totalg").val(roundNumber(totals+iva,2));
	$("#totalg_val").text(nformat(totals+iva,2));

}

function add_itnotascc(){
	var htm = <?php echo $campos; ?>;
	can = itnotascc_cont.toString();
	con = (itnotascc_cont+1).toString();
	htm = htm.replace(/<#i#>/g,can);
	htm = htm.replace(/<#o#>/g,con);
	$("#__INPL__").after(htm);
	$("#cana_"+can).numeric(".");
	$('#codigo_'+can).focus();
	itnotascc_cont=itnotascc_cont+1;
}
function del_itnotascc(id){
	id = id.toString();
	$('#tr_itnotascc_'+id).remove();
	totalizar();
}
</script>
<?php } ?>
<table align='center' width="85%" style='background: #EEEEEE'>
	<tr>
<?php if ($form->_status=='show') { ?>
		<td>
		<a href="#" onclick="window.open('<?php echo base_url() ?>formatos/verhtml/NOTASCC/<?php echo $form->id->value ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" ><img src='<?php echo base_url() ?>images/html_icon.gif'></a>
		<a href="#" onclick="window.open('<?php echo base_url() ?>formatos/ver/NOTASCC/<?php echo $form->id->value ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" ><img src='<?php echo base_url() ?>images/pdf_logo.gif'></a>  
		 <td>
<?php } ?>
        <td width="95%" align="right"><?php echo $container_tr?><?php echo $container_br?></td>
	</tr>
</table>
<table align='center' width="85%">
  <tr>
	  <td><?php  if ($form->tipo_doc->value=='X') 
	  echo "<div style='font-size:14px;font-weight:bold;background: #B40404;color: #FFFFFF' align='center'>***DOCUMENTO ANULADO***</div>"; ?>	  
	  </td>
  </tr>
	<tr>
	<td><a href="#" onclick="window.open('<?php echo base_url() ?>fsiigo/notac/<?php echo $form->numero->value ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" ><img src='<?php echo base_url() ?>images/icono_impresora.gif' /></a></td>
	</tr>
	<tr>
	  <td>
		<table width='100%' border=0><tr><td width="50%" >
			<fieldset style='border: 2px outset #9AC8DA;background: #FFFFFF;'>
			<legend class="titulofieldset" style='color: #2E4B77;'><?php if($form->_status=='show') echo  $form->serie->output.'-'.$form->numero->output; ?></legend>
			<table width="100%" style="margin: 0; width: 100%;">
			<tr>
				<td class="littletableheader"><?=$form->numero->label  ?></td>
				<td class="littletablerow" align="left"><?=$form->serie->output ?>-<?=$form->numero->output ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->fecha->label;    ?>*</td>
				<td class="littletablerow">   <?php echo $form->fecha->output;   ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->vence->label;    ?>*</td>
				<td class="littletablerow">   <?php echo $form->vence->output;   ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->vd->label     ?></td>
				<td class="littletablerow"><?php echo $form->vd->output    ?></td>
			</tr>
			 <tr>
			  <td class="littletableheader"><?php echo $form->formap->label     ?></td>
			  <td class="littletablerow"><?php echo $form->formap->output    ?></td>
			 </tr>
			 <tr>
				<td class="littletableheader"><?php echo $form->ccosto->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->ccosto->output;   ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->cuentai->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->cuentai->output;   ?></td>
			</tr>
			 <tr>
				<td class="littletableheader"><?php echo $form->almacen->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->almacen->output;   ?></td>
			</tr>
			</table>
			</fieldset>
		</td><td>
			<fieldset style='border: 2px outset #9AC8DA;background: #FFFFFF;'>
			<legend  class="titulofieldset" style='color: #2E4B77;'>Identificaci&oacute;n del Cliente</legend>
			<table width="100%" style="margin: 0; width: 100%;">
			<tr>
				<td width="33%" class="littletableheader"><?php echo $form->cliente->label;  ?>&nbsp;</td>
				<td width="21%" class="littletablerow">
			<a href='<?php echo base_url()."ventas/sclifyco/dataedit/show/$id" ?>'><?php echo $form->cliente->output ?></a>				</td>
				<td width="46%" class="littletablerow"><?php echo $form->nombre->output;  ?>&nbsp;</td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->rifci->label; ?>&nbsp;</td>
				<td class="littletablerow" colspan='2'><?php echo $form->rifci->output;   ?>&nbsp;</td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->direc->label  ?>&nbsp;</td>
				<td class="littletablerow" colspan='2'><?php echo $form->direc->output ?>&nbsp;</td>
			</tr>
			</table>
			</fieldset>
			<fieldset style='border: 2px outset #9AC8DA;background: #FFFFFF;'>
			<legend  class="titulofieldset" style='color: #2E4B77;'>Documento de Referencia</legend>
			<table width="100%" style="margin: 0; width: 100%;">
			 <tr>
			  <td class="littletableheader"><?php echo $form->serief->label     ?></td>
			  <td class="littletablerow"><?php echo $form->serief->output    ?>-<?php echo $form->numerof->output    ?></td>
			 </tr>
			  <tr>
			  <td class="littletableheader"><?php echo $form->fechaf->label     ?></td>
			  <td class="littletablerow"><?php echo $form->fechaf->output    ?></td>
			 </tr>
			  <tr>
			  <td class="littletableheader"><?php echo $form->moneda->label     ?></td>
			  <td class="littletablerow"><?php echo $form->moneda->output    ?></td>
			 </tr>
			 <tr>
			  <td class="littletableheader"><?php echo $form->cambio->label     ?></td>
			  <td class="littletablerow"><?php echo $form->cambio->output    ?></td>
			 </tr>
			</table>
			</fieldset>
		</td><tr></table>
		<br>
	</td>
	</tr>
	<tr>
		<td>
<div style='overflow:auto;border: 1px solid #9AC8DA;background: #FAFAFA;height:200px'>
		<table width='95%' border='0' align="center">
			<tr id='__INPL__' class="littletablerow">
				<td bgcolor='#527D9E'>C&oacute;digo</td>
				<td bgcolor='#527D9E'>Descripci&oacute;n</td>
				<td bgcolor='#527D9E'>Unidad</td>
				<td bgcolor='#527D9E'>Cantidad</td>
				<td bgcolor='#527D9E'>Precio sin IGV</td>
				<td bgcolor='#527D9E'>Importe</td>
				<?php if($form->_status!='show') {?>
					<td class="littletableheader">&nbsp;</td>
				<?php } ?>
			</tr>

			<?php for($i=0;$i<$form->max_rel_count['itnotascc'];$i++) {
				$it_codigo  = "codigo_$i";
				$it_desca   = "desca_$i";
				$it_unidad  = "unidad_$i";
				$it_cana    = "cana_$i";
				$it_preca   = "preca_$i";
				$it_importe = "importe_$i";


			?>

			<tr id='tr_itnotascc_<?php echo $i; ?>'>
				<td class="littletablerow" align="left" ><?php echo $form->$it_codigo->output; ?></td>
				<td align="left" class="littletablerow" ><?php echo $form->$it_desca->output;  ?></td>
				<td align="left" class="littletablerow" ><?php echo $form->$it_unidad->output;   ?></td>
				<td class="littletablerow" align="left"><?php echo $form->$it_cana->output;   ?></td>
				<td class="littletablerow" align="left"><?php echo $form->$it_preca->output;  ?></td>
				<td class="littletablerow" align="left"><?php echo $form->$it_importe->output;?></td>

				<?php if($form->_status!='show') {?>
				<td class="littletablerow">
					<a href='#' onclick='del_itnotascc(<?=$i ?>);return false;'><?php echo img("images/delete.jpg"); ?></a>				</td>
				<?php } ?>
			</tr>
			<?php } ?>

			<tr id='__UTPL__'>
				<td id='cueca'></td>
			</tr>
		</table>
		</div>
		<?php echo $container_bl ?>
		</td>
	</tr>
	<tr>
		<td>
		<fieldset style='border: 2px outset #9AC8DA;background: #EFEFEF;'>
		<legend  class="titulofieldset" style='color: #2E4B77;' align="right">-- Totales --</legend>
		<table width='100%'>
			<tr>
				<td width="15%" class="littletableheader"><?php echo $form->condi1->label;  ?></td>
				<td width="55%"class="littletablerow"><?php echo $form->condi1->output;  ?></td>
				<td width="15%" align='right' class="littletableheader"><?php echo $form->totals->label;  ?></td>
				<td width="15%" align='right' class="littletablerow"><b id='totals_val'><?php echo nformat($form->totals->value); ?></b></td>
			</tr>
			<tr>	
				<td colspan=3  class="littletableheader" align='right'><?php echo $form->ivat->label;    ?> <?php echo nformat($this->datasis->dameval("SELECT tasa FROM civa ORDER BY fecha DESC"),0); ?> %</b></td>
				<td class="littletablerow" align='right' ><b id='ivat_val'><?php echo nformat($form->ivat->value); ?></td>
			</tr>
			<tr>
				<td colspan=3  class="littletableheader"align='right' ><?php echo $form->totalg->label;  ?></td>
				<td class="littletablerow" align='right' ><b id='totalg_val'><?php echo nformat($form->totalg->value); ?></b></td>
			</tr> 
		</table>
		</fieldset>
		</td>
	</tr>
</table>
<?php echo $form_end; ?>
<?php endif; ?>
